import { Window_Command } from "@/windows/Window_Command.js";
import { TextManager } from "@/managers/TextManager.js";

export class Window_MenuCommand extends Window_Command {
    constructor(width,height) {
        super(width,height);
    }

    makeCommands() {
        this.addMainCommands();
        this.addOptionsCommand();
        this.addSaveCommand();
        this.addGameEndCommand();
    }

    addMainCommands() {
        let disabled = false;//!this.areMainCommandsEnabled();
        if (this.needsCommand('item')) {
            this.addCommand(TextManager.item,null, disabled);
        }
        if (this.needsCommand('skill')) {
            this.addCommand(TextManager.skill, null, disabled);
        }
        if (this.needsCommand('equip')) {
            this.addCommand(TextManager.equip, null, disabled);
        }
        if (this.needsCommand('status')) {
            this.addCommand(TextManager.status, null, disabled);
        }
    }

    addOptionsCommand() {
        if (this.needsCommand('options')) {
            let enabled = this.isOptionsEnabled();
            this.addCommand(TextManager.options, null, !enabled);
        }
    }

    addSaveCommand() {
        if (this.needsCommand('save')) {
            this.addCommand(TextManager.save, null, !this.isSaveEnabled());
        }
    }

    addGameEndCommand() {
        this.addCommand(TextManager.gameEnd, null, !this.isGameEndEnabled());
    }

    needsCommand(name) {
        let flags = $dataSystem.menuCommands;
        if (flags) {
            switch (name) {
            case 'item':
                return flags[0];
            case 'skill':
                return flags[1];
            case 'equip':
                return flags[2];
            case 'status':
                return flags[3];
            case 'save':
                return flags[5];
            }
        }
        return true;
    }

    areMainCommandsEnabled() {
        return $gameParty.exists();
    }

    isOptionsEnabled() {
        return true;
    }

    isSaveEnabled() {
        return $gameSystem.isSaveEnabled();
    }

    isGameEndEnabled() {
        return true;
    }
}
